package com.bawie.util;

public class PageUtil {

	private int currentPage;
	
	private int prevPage;
	
	private int nextPage;
	
	private int lastPage;
	
	private int count;
	
	private int pageSize;
	
	private int pageCount;
	
	private String mohu;
	
	private String page;
	
	
	//���췽��                              ��һ��������ǰҳ                  ������               ÿҳ����                      ģ����ѯ�ֶ�
	public PageUtil(String currentPage,int count,int pageSize,String mohu) {
		//��ʼ��currentPage  ��string ת��Ϊ int
		initCurrentPage(currentPage);
		//������һҳ
		initPrevPage();
		//�������һҳ
		initLastPage(count, pageSize);
		//������һҳ
		initNextPage();
		initPageCount();
		this.mohu=mohu;
	}
	
	//currentPage ����ת����int ����  
	private void initCurrentPage(String currentPage){
		//�ж�currentPage�Ƿ���ת  ���ж��Ƿ�Ϊnull����Ϊ""
		//�����  ���ǾͰѵ�ǰҳ������Ϊ��һҳ
		if(currentPage==null||currentPage.isEmpty()){
			currentPage = "1";
		}
		//���ַ�����ת����int
		this.currentPage = Integer.valueOf(currentPage);
	}
	//������һҳ
	private void initPrevPage(){
		//�жϵ�ǰҳ�Ƿ�Ϊ��һҳ������ǣ���һҳΪ��һҳ
		if(this.currentPage==1){
			this.prevPage = 1;
		}else{
			//�������һ����ô��һҳΪ����ǰҳ-1
			this.prevPage = this.currentPage-1;
		}
	}
	private void initLastPage(int count,int pageSize){
		this.count = count;
		this.pageSize = pageSize;
		if(count%pageSize==0){
			this.lastPage = count/pageSize;
		}else{
			this.lastPage = count/pageSize+1;
		}
	}
	
	private void initNextPage(){
		if(this.currentPage==this.lastPage){
			this.nextPage = this.currentPage;
		}else{
			this.nextPage = this.currentPage+1;
		}
	}
	
	private void initPageCount(){
		this.pageCount = (this.currentPage-1)*this.pageSize;
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public int getPrevPage() {
		return prevPage;
	}

	public int getNextPage() {
		return nextPage;
	}

	public int getLastPage() {
		return lastPage;
	}

	public int getCount() {
		return count;
	}

	public int getPageSize() {
		return pageSize;
	}

	public int getPageCount() {
		return pageCount;
	}

	public String getMohu() {
		return mohu;
	}
	public String getPage() {
		String str = "";
		str +="��"+this.currentPage+"/"+this.lastPage+"ҳ";
		str +="<input type='button' value='��ҳ' onclick='fenye(1)' >";
		str +="<input type='button' value='��һҳ' onclick='fenye("+this.prevPage+")' >";
		str +="<input type='button' value='��һҳ' onclick='fenye("+this.nextPage+")' >";
		str +="<input type='button' value='βҳ' onclick='fenye("+this.lastPage+")' >";
		return str;
	}
	
	
	
}
